package org.pine.dictionary.bean;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * <p>
 * 通用响应结果vo
 * </p>
 *
 * @author pine
 * @since 2024-05-16
 */
@Data
@Schema(title = "通用响应结果")
@NoArgsConstructor
public class ResultVo<T> implements Serializable {

    @Serial
    private static final long serialVersionUID = -5187628486516699925L;

    /**
     * 响应数据
     */
    @Schema(title = "data", description = "响应数据")
    private T data;

    /**
     * 响应编码
     */
    @Schema(title = "code", description = "响应编码", defaultValue = "0")
    private String code;

    /**
     * 响应信息，比如错误描述
     */
    @Schema(title = "message", description = "响应信息")
    private String message;

    /**
     * 日志ID
     */
    @JsonProperty("logId")
    @Schema(title = "logId", description = "日志ID")
    private String logId;

    /**
     * 时间戳
     */
    @Schema(title = "timestamp", description = "时间戳")
    private Long timestamp;

    public ResultVo(T data, String code, String message) {
        this.data = data;
        this.code = code;
        this.message = message;
        this.timestamp = System.currentTimeMillis();
        this.logId = LogId.get();
    }
}
